package com.sc.nft.dao;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.Push;
import com.sc.nft.entity.vo.NoticeInfoVO;
import com.sc.nft.entity.vo.ZhiTanNoticeVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.NoticeInfo;
import com.sc.nft.mapper.NoticeInfoMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_notice_info)数据DAO
 *
 * @author rdg
 * @since 2022-05-30 10:09:02
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class NoticeInfoDao extends ServiceImpl<NoticeInfoMapper, NoticeInfo> {

    public List<NoticeInfoVO> getNoticeInfos() {
        return baseMapper.getNoticeInfos();
    }

    public Page<NoticeInfoVO> getNoticeInfosPage(Page page) {
        return baseMapper.getNoticeInfosPage(page);
    }

    public Page<NoticeInfo> listPagedNotice(int pageNo, int pageSize) {
        LambdaQueryWrapper<NoticeInfo> noticeInfoWrapper = new LambdaQueryWrapper<>();
        noticeInfoWrapper.orderByDesc(NoticeInfo::getId);
        return page(new Page<>(pageNo,pageSize),noticeInfoWrapper);
    }

    /**
     * 分页获取公告（智探）
     * @param page
     * @return
     */
    public List<ZhiTanNoticeVO> noticeList(Integer page, Integer pageSize) {
        return baseMapper.noticeList(new Page<>(page,pageSize)).getRecords();
    }

    public List<NoticeInfoVO> listNotice(Long announcementFrequency) {
        return baseMapper.listNotice(announcementFrequency);
    }
    public NoticeInfoVO getOneById(Long id) {
        return baseMapper.getOneById(id);
    }

    public List<NoticeInfo> getUnPushedScheduleListFiveMinuteLater() {
        LambdaQueryWrapper<NoticeInfo> noticeInfoWrapper = new LambdaQueryWrapper<>();
        noticeInfoWrapper.eq(NoticeInfo::getIsPushed, false);
        noticeInfoWrapper.eq(NoticeInfo::getEnablePush, true);
        noticeInfoWrapper.isNotNull(NoticeInfo::getStartTime);
        noticeInfoWrapper.isNotNull(NoticeInfo::getEndTime);
        noticeInfoWrapper.le(NoticeInfo::getStartTime, DateUtil.date().offsetNew(DateField.MINUTE, 5));
        noticeInfoWrapper.ge(NoticeInfo::getStartTime, DateUtil.date().offsetNew(DateField.MINUTE, -30));
        return baseMapper.selectList(noticeInfoWrapper);
    }

}